package com.itheima.common;/*
 *      .--,       .--,
 *     ( (  \.---./  ) )
 *     '.__/o   o\__.'
 *        {=  ^  =}
 *         >  -  <
 *        /       \
 *       //       \\
 *      //|   .   |\\
 *      "'\       /'"_.-~^`'-.
 *         \  _  /--'         `
 *       ___)( )(___
 *      (((__) (__)))    高山仰止,景行行止.虽不能至,心向往之。
 *
 * @author JiaoDaoNiu
 * @create 2022-09-24-19:26
 */


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
      log.info("公共字段自动填充了");
      metaObject.setValue("createTime",LocalDateTime.now());
      metaObject.setValue("updateTime",LocalDateTime.now());
   /*   metaObject.setValue("createUser",new Long(1) );
      metaObject.setValue("updateUser",new Long(1));  */
        //这边更新线程副本传递过来的id
      metaObject.setValue("createUser",BaseContext.getCurrentId() );
      metaObject.setValue("updateUser",BaseContext.getCurrentId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段自动更新了");
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("updateUser",BaseContext.getCurrentId());

    }




}
